<?xml version="1.0" encoding="utf-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE >
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>销售机会</title>
		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
		<script src="https://unpkg.com/vue/dist/vue.js"></script>
		<!-- 引入组件库 -->
		<script src="https://unpkg.com/element-ui/lib/index.js"></script>
		<!-- 引入axios -->
		<script src="../js/axios.js"></script>
		<script src="../js/qs.js"></script>
		<!-- 导入jquery -->
		<script src="../js/jquery.min.js"></script>
		<style type="text/css">
.loading{
        width: 100%;
        height: 100%;
        position: fixed;
        background-color: white;
        top: 0px;
        left: 0px;
        z-index: 100;
}	
.loading .bigpic{
    width: 104px;
    height: 104px;
    background-image: url("../imgs/loading.gif") ;
    position: absolute;
    top: 0px;
    bottom: 0px;
    right: 0px;
    left: 0px;
    margin: auto;
}
.select{
width:130px;
}
 .bg-purple {
 
  }
  .grid-content {
    border-radius: 4px;
  }
.undo{
    background-image: url("") ;
}
		</style>
<script>

$(document).ready(function(){

/* 	  $("#salThme").blur(function(){

	    $(this).hide();

	    $(this).parent().html($(this).val());

	  });

	}); */
	
 document.addEventListener("readystatechange",function(){
		//对象尚未初始化
		if(document.readyState=="uninitialized"){
			console.log("readystatechange-uninitialized");
		}
		//对象正在加载
		if(document.readyState=="loading"){
			console.log("readystatechange-loading");
		}
		//对象加载数据完成
		if(document.readyState=="loaded"){
			console.log("readystatechange-loaded");
		}
		//可以操作对象，但还没完全加载
		if(document.readyState=="interactive"){
			console.log("readystatechange-interactive");
		}
		//对象已经加载完毕
	     if (document.readyState == "complete") {
	       console.log("readystatechange-complete");
	      }
	  }); 
	$(function(){
	    //读取数据是否加载成功
	    document.onreadystatechange=function(){
	        //判断页面读取状态   页面读取状态一共四中
	        if(document.readyState == "complete"){
	        //载入完成fadeOut();移除div样式
	            $(".loading").fadeOut();
	        }
	    } 
	});
	
	});
</script>

		<!--<style type="text/css">
			//这段代码是让分割线中间加文字
.order {
   height: 60px;
   line-height: 60px;
   text-align: center;
}
 .order .line {
   display: inline-block;
   width: 150px;
   border-top: 1px solid #ccc ;
}
.order .txt {
   color: #686868;
   vertical-align: middle;
}
		</style>-->
	</head>
		<body >
				<div class="loading">
			<div class="bigpic"><div class="bigpic"></div></div>
		</div>
		<div id="bigbox" >
	<div style="float: right;display: block;"  >
	<!-- 这里是弹窗--start-->					
					<el-dialog  :visible.sync="dialogFormVisible" width="70%" style="background-color: #D3D0D0;margin-top:-60px;" :modal="false" :close-on-press-escape="false" :close-on-click-modal="false" :show-close="false">	
<!-- 						<el-form-item >
							</el-form-item>  -->
<!-- 						<hr style="border: 1px solid #000000;margin-top: -15px;" /> -->
								<div style="margin-top: -40px;" >
									<el-row >
									<el-col :span="4" style="line-height:20px;margin-top:7px;">
								<span style="font-size:20px;">销售机会</span>
									</el-col>
										<el-col :span="15">	
										</el-col>							
									<el-col :span="5" style="float:right;margin-right:-30px;">
								<el-button @click="editInput" v-if="showText">编辑</el-button>
								<el-button  @click="submitForm('form')" >保存</el-button>
									</el-col>
								</el-row>
								</div>
						<hr style="border: 1px solid #000000;" /> 
						<p style="font-size: 15px;color: #333333;margin: 20px 0px 20px 0px;font-weight: 900;">机会</p>
						<hr style="border: 0.5px solid #EEEEEE;" />				
						<el-form :model="form" :rules="rules" label-width="150px" ref="form"  style="height: 1120px;">						
	
							<el-row >
								<el-col :span="12">
									<el-form-item label="机会主题:" prop="salTheme">
										<el-input v-model="form.salTheme" id="salThme" v-show="showInput"></el-input>
										<span v-show="showText">{{form.salTheme}}</span>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="更新时间:">
										<el-date-picker v-model="form.salUpdatetime" align="right" type="date" placeholder=" " :picker-options="pickerOptions1" :disabled="true" v-show="showInput">
										</el-date-picker>
											<span v-show="showText">{{'2018-8-11'}}</span>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row >
								<el-col :span="12">
										<el-form-item label="状  态:">
   											 <el-radio v-model="form.salState" label="1287">跟踪</el-radio>
  											 <el-radio v-model="form.salState" label="1288">成功</el-radio>
  											 <el-radio v-model="form.salState" label="1289">失败</el-radio>
  											 <el-radio v-model="form.salState" label="1290">搁置</el-radio> 	
   											 <el-radio v-model="form.salState" label="1291">失效</el-radio>  											 

											</el-form-item>
								</el-col>
								<el-col :span="12">
						<el-form-item label="对应客户:" prop="customer">
						<!-- :fetch-suggestions="querySearchAsync"customerFlag:false,soltIdFlag:false-->
						<el-autocomplete v-model.trim="form.customer" :fetch-suggestions="querySearchAsync"  placeholder="请输入内容" @select="handleSelect" @focus="customerFlag=true" @blur="customerFlag=false" v-show="showInput">
						 <i slot="prefix" class="el-input__icon el-icon-search"></i>
						</el-autocomplete>
						<span v-show="showText">{{form.customer}}</span>
					    	</el-form-item>
								</el-col>
							</el-row>
							<hr style="border: 0.5px solid #EEEEEE;margin-top: 15px;" />
							<p style="font-size: 15px;color: #333333;margin: 20px 0px 20px 0px;font-weight: 900;">基本信息</p>
							<hr style="border: 0.5px solid #EEEEEE;" />
							<!--<hr style="border: 0.5px solid #333333;margin: 35px 0px 35px 0px;" />-->
							
							<el-row style="margin-left: 10px;">
								<el-col :span="12">
								<el-form-item label="联系人:">
										<el-select v-model="form.contact" filterable placeholder="未选" v-show="showInput" required>
											<el-option v-for="item in contacts" :key="item.con" :label="item.conlabel" :value="item.con">
											</el-option>
											</el-select>
											<span v-show="showText">{{form.contact}}</span>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="类型:">
										<el-select v-model="form.salType" filterable placeholder="未选" v-show="showInput" required>
											<el-option v-for="item in salTypes" :key="item.value" :label="item.label" :value="item.value">
											</el-option>
												</el-select>
											<el-tooltip content="Bottom center" placement="bottom" v-show="showInput">
												<div slot="content">数据字典</div>
												<i class="el-icon-document" id="newtool"></i>
											</el-tooltip>
										<span v-show="showText">{{form.salType}}</span>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row style="margin-left: 10px;">
								<el-col :span="12">
									<el-form-item label="来源:">
										<el-select v-model="form.salSource" filterable placeholder="未选" v-show="showInput" required>
											<el-option v-for="item in salSources" :key="item.value" :label="item.label" :value="item.value">
											</el-option>
												</el-select>
											<el-tooltip content="Bottom center" placement="bottom" v-show="showInput">
												<div slot="content">数据字典</div>
												<i class="el-icon-document" id="newtool"></i>
											</el-tooltip>
											<span v-show="showText">{{form.salSource}}</span>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="负责人:">
										<!-- <el-select v-model="form.sotlId" filterable placeholder="索引">
											<el-option v-for="item in users" :key="item.value" :label="item.label" :value="item.value">
											</el-option>											
												</el-select> -->
						<el-autocomplete v-model.trim="form.sotlId" :fetch-suggestions="querySearchAsync"  placeholder="请输入内容" @select="handleSelect" @focus="soltIdFlag=true" @blur="soltIdFlag=false" v-show="showInput">
								 <i slot="prefix" class="el-input__icon el-icon-search"></i>
						</el-autocomplete>			
								<span v-show="showText">{{form.sotlId}}</span>									
									</el-form-item>
								</el-col>								
							</el-row>
<!-- 							<el-row style="margin-left: 10px;">
								<el-col :span="12">
									<el-form-item label="负责人:">
										<el-select v-model="form.sotlId" filterable placeholder="索引">
											<el-option v-for="item in users" :key="item.value" :label="item.label" :value="item.value">
											</el-option>											
												</el-select>
						<el-autocomplete v-model.trim="form.sotlId" :fetch-suggestions="querySearchAsync"  placeholder="请输入内容" @select="handleSelect" @focus="soltIdFlag=true" @blur="soltIdFlag=false">
								 <i slot="prefix" class="el-input__icon el-icon-search"></i>
						</el-autocomplete>												
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="提供人:">
										<el-select v-model="form.provider" filterable placeholder="未选">
											<el-option v-for="item in providers" :key="item.value" :label="item.label" :value="item.value">
											</el-option>
												</el-select>
											<el-tooltip content="Bottom center" placement="bottom">
												<div slot="content">数据字典</div>
												<i class="el-icon-document" id="newtool"></i>
											</el-tooltip>
									</el-form-item>
								</el-col>
							</el-row> -->
					<el-row style="margin-left: 10px;">
						<el-form-item label="客户需求:">
						<el-input type="textarea"  style="width:82%" :rows="5"  v-model="form.custDemand" v-show="showInput"> </el-input>
						<span v-show="showText">{{form.custDemand}}</span>	
						</el-form-item>
						</el-row>
							<hr style="border: 0.5px solid #EEEEEE;margin-top: 15px;" />
							<p style="font-size: 15px;color: #333333;margin: 20px 0px 20px 0px;font-weight: 900;">预期</p>
							<hr style="border: 0.5px solid #EEEEEE;" />	
							<el-row style="margin-left: 10px;">
								<el-col :span="12">
									<el-form-item label="预计签单日期:" prop="sotlDate">
										<el-date-picker v-model="form.sotlDate" align="right" type="date" placeholder=" "  v-show="showInput">
										</el-date-picker>
										<span v-show="showText">{{'2018-12-25'}}</span>	
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="可能性:" clearable="true">
										<el-select v-model="form.salPossibility" filterable placeholder="未选" v-show="showInput" >
											<el-option v-for="item in possibilities" :key="item.value" :label="item.label" :value="item.value">
											</el-option>
												</el-select>
												<span v-show="showText">{{form.salPossibility}}</span>	
									</el-form-item>
								</el-col>
							</el-row>
							<el-row style="margin-left: 10px;">	
								<el-col :span="12">
									<el-form-item label="预期金额:" prop="sotlMoney" v-show="showInput">
									<el-input v-model.number="form.sotlMoney" style="width:57%;"></el-input>
									<span v-show="showText">{{form.sotlMoney}}</span>	
									</el-form-item>
									
								</el-col>
							</el-row>						
							<hr style="border: 0.5px solid #EEEEEE;margin-top: 15px;" />
							<p style="font-size: 15px;color: #333333;margin: 20px 0px 20px 0px;font-weight: 900;">当前状态</p>
							<hr style="border: 0.5px solid #EEEEEE;" />	
							<el-row style="margin-left: 10px;">
								<el-col :span="12">
									<el-form-item label="星 标:"> 
   											 <el-radio v-model="form.starStandard" label="1317"><label for="star">无</label></el-radio>
  											 <el-radio v-model="form.starStandard" label="1318"><label for="starRed"><img src="../imgs/sales/starBlue.png"></label></el-radio>
  											 <el-radio v-model="form.starStandard" label="1319"><label for="starYellow"><img src="../imgs/sales/starYellow.png"></label></el-radio>
  											 <el-radio v-model="form.starStandard" label="1320"><label for="starBlue"><img src="../imgs/sales/starBlue.png"></label></el-radio> 	
   											 <el-radio v-model="form.starStandard" label="1321"><label for="starGreen"><img src="../imgs/sales/starGreen.png"></label></el-radio> 
											 <el-radio v-model="form.starStandard" label="1322"><label for="starPurple"><img src="../imgs/sales/starPurple.png"></label></el-radio> 	
									
									</el-form-item>
								</el-col>
								<el-col :span="12">
								<el-form-item label="阶段:" prop="salStage">							
										<el-select v-model="form.salStage" filterable placeholder="索引" v-show="showInput">
											<el-option v-for="c in stages" :key="c.value" :label="c.label" :value="c.value">
											</el-option>
										</el-select>
										<span v-show="showText">{{form.salStage}}</span>	
									</el-form-item>
								</el-col>
							</el-row>
							
							<el-row style="margin-left: 10px;">	
								<el-col :span="24">
								<el-form-item label="阶段备注:">
									<el-input v-model="form.salStageNotes" style="width:82%" v-show="showInput"></el-input>
									<span v-show="showText">{{form.salStageNotes}}</span>
									</el-form-item>
								</el-col>
							</el-row>
							
	 						<el-row style="margin-left: 10px;">	
								<el-col :span="24">
								<el-form-item label="阶段停留:"style="width:82%" v-model="form.salStageStop" v-show="showInput">
									<span v-show="showText">{{form.salStageStop}}</span>
								</el-form-item>
								</el-col>
							</el-row>
							
							<el-row style="margin-left: 10px;">	
								<el-col :span="18">
								<el-form-item label="跟踪日志:" >
									<el-input v-model="salesOpportunityTrackingLogs" :disabled="true" style="width:82%"  type="textarea"   :rows="4" v-show="showInput" readonly></el-input>
								<!-- 	style="margin-left:160px;" -->
									<span v-show="showText" >{{salesOpportunityTrackingLogs}}</span>
									</el-form-item>

								</el-col>
							</el-row>
						<hr style="border: 0.5px solid #EEEEEE;" />						
							<el-form-item style="float: right;margin-top: 40px;">
								<el-button @click="cancelForm('form')">编辑</el-button>
								<el-button type="primary" @click="submitForm('form')" >保存</el-button>
							</el-form-item> 
						</el-form>
					</el-dialog>
					<!--这里是弹窗--end-->
				</div>	
		</div>
						
	</body>
	<script type="text/jscript">
	var Main1 = {
			
			data() {
				//检查输入是否为数字,是否为空  
			      var checkSoltMoney = (rule, value, callback) => {
			          setTimeout(() => {
			        	 if(value==null||value==''){
			        		 callback();
			        	 }
			            if (!Number.isInteger(value)) {
			              callback(new Error('请输入数字值'));
			            } else {
			                callback();
			            }
			          }, 1000);
			        };
			    //检查机会主题是否重复，是否为空    
				   var checkSalTheme = (rule, value, callback) => {
					   if(value==null||value==''){
						   callback(new Error('机会主题为必填项'));  
					   }
					   var _this=this;
					 	axios.get("/sales/findBySalTheme",
			           			{
							params:{
								salTheme:value
									}
	           					}
			           			//ajax请求成功的回调函数
			          			).then(function(response){					          				
			           			console.log("回调成功，获取了服务器端返回的值v");
			           			console.log(response.data);//返回id值
			           			console.log(_this.form.salId);
			           			if(response.data){
			           				if(_this.form.salId==response.data){
			           					callback();						           					
			           				}else{
							           	 callback(new Error('该机会主题已存在，请重新命名'));							           					
			           				}
		           				
			           			}else{
			           				callback();
			           			}
			           	}).catch(function(){
			           	 callback(new Error('查询有误'));
			           	});
					 	
				       };
				 //检查签单预计时间是否大于等于今天      
			      var  checkSotlDate=(rule, value, callback) => {
			    	  //Thu Jul 12 2018 00:00:00 GMT+0800 (中国标准时间)
			    	  	//将当前日期转换成yyyy-MM-dd格式
			    	  	//var selectDate = value.format('yyyy-MM-dd');
						//alert(this.form.salTheme);
			    	 	 //将当前时间转换成yyyy-MM-dd
			    	 	 if(value==null||value==''){
			    	 		 callback();
			    	 	 }else{
			    	 		/* if(this.form.salId!=null){
			    	 			 
			    	 		 }*/
								var t2 =0;
			    	 		 try{
			    	 			 t2=new Date(value.replace("-", "/").replace("-", "/"));
			    	 			callback();
			    	 		 }catch(err)
			    	 		 {
						    	   var mydate = new Date();
									var str1 = "" + mydate.getFullYear() + "-";
									str1 += (mydate.getMonth()+1) + "-";
									str1 += mydate.getDate();
						    	 	 //将获取的时间转换成yyyy-MM-dd								    	 	 
										var str2 = "" + value.getFullYear() + "-";
										str2 += (value.getMonth()+1) + "-";
										str2 += value.getDate();
							    	//可将yyyy-MM-dd格式转成可以进行比较的yyyy/MM/dd格式										
									var tady=new Date(str1.replace("-", "/").replace("-", "/"));
				    	 			 t2=new Date(str2.replace("-", "/").replace("-", "/"));
						          setTimeout(() => {
						            if (t2<tady) {
						              callback(new Error('签单时间不能小于今天'));
						            } else {
						                callback();
						            }
						          }, 1000);												
						       };

			    	 	 }
				       };
				     //检查输入的客户数据是否存在,是否为空  
					 var checkCustomer = (rule, value, callback) => {
						   if(value==null||value==''){
							   callback(new Error('对应客户为必填项'));  
						   }
					          setTimeout(() => {
					            if (this.restaurants==null||this.restaurants=='') {
					              callback(new Error('您输入的客户名称不存在，请确认后再输入'));
					            } else {
					                callback();
					            }
					          }, 1000);
					   };
				return{
					json:${sales},
					dialogFormVisible:true,
					showInput:false,
					showText:true,
					salesOpportunityTrackingLogs:'',//这个值是为了显示销售机会跟踪日志
					form: {
						custDemand:'',
						salPossibility:'',
						salSource:'',
						salStage:'',
						salStageNotes:'',
						salStageStop:'',
						salState:'1287',
						salTheme:'飞鱼天下第一',
						salType:'',
						salUpdatetime:new Date(),
						sotlDate:new Date(),
						sotlMoney:'',
						starStandard:'1317',
						customer:'',
						salId:'',
						contact:'',
						state:1,
						sotlId:''
					},
			          value7:'',
			          value7Copy:'',
			          printFlag1:false,//这个值是为了在打印的时候去掉一些不必要的元素
			          printFlag2:false,//这个值是为了在打印的时候去掉一些不必要的元素
			          value7Flag:false,
			          option:'',
			          obj2:null,
			          state1:'',
			          state1Copy:'',
			          salStageCopy:'',//这个是销售机会负责人的copy
			          matchFlag:false,
			          state1Flag:false,
			          state1Session:false,
			          select:'1',
			          selectCopy:'1',
					salId:'',
					contacts:"",
					salTypes:"",
					salSources:' ',
					providers:' ',
					users:' ',
					possibilities:' ',
					stages:' ',
					gdID: '',
					conID:'',
					value8: '',
					valuecust: '',
					DId:0,
					data:[],
					flag:false,
					customerFlag:false,
					soltIdFlag:false,
				rules:{
					customer:[
					{	
						required: true,validator:checkCustomer, trigger: 'change'
					}],
					salStage:[
					{	
						required: true,
						message: '请至少选择一个阶段',
						trigger: 'change'
					}	
					],
					sotlMoney:[
						{
							validator:checkSoltMoney, trigger: 'blur' 
						}
					],
					sotlDate:[{
						validator:checkSotlDate, trigger: 'change'
					}],
					salTheme:[{
						required: true,validator:checkSalTheme, trigger: 'blur'										
					}]									
				},
				/* 日期选择 */
				pickerOptions1: {
					disabledDate(time) {
						return time.getTime() > Date.now();
					},
					shortcuts: [{
						text: '今天',
						onClick(picker) {
							picker.$emit('pick', new Date());
						}
					}, {
						text: '昨天',
						onClick(picker) {
							const date = new Date();
							date.setTime(date.getTime() - 3600 * 1000 * 24);
							picker.$emit('pick', date);
						}
					}, {
						text: '一周前',
						onClick(picker) {
							const date = new Date();
							date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
							picker.$emit('pick', date);
						}
					}]
				},
				gettoday: new Date(),
				getDate:'',
				gettime: new Date(),
				prostarttoday:'',
				prosalettoday:'',
		        restaurants: [],
		        timeout:  null
			}
		},
			methods:{
				//这里是显示input的编辑方法
				editInput(){
				//	alert();
					this.showInput=true;
					this.showText=false;
					
				},
				/*
				加载表单时的初始化
				*/						
				initForm(array){
           			var form='';
           			var json=array[0];
           			var _this=this;
       				form=this.form;
					
					/*
					custDemand:'',
					salPossibility:'',
					salSource:'',
					salStage:'',
					salStageNotes:'',
					salStageStop:'',
					salState:'1287',
					salTheme:'',
					salType:'',
					salUpdatetime:new Date(),
					sotlDate:new Date(),
					sotlMoney:'',
					starStandard:'1317',
					customer:'',
					salId:'',
					contact:''	
				  */

	           		form.salId=json.salId+'';	      				
	           		form.starStandard=json.starStandard+'';
	           		form.salState=json.salState+'';	
	           		form.sotlDate=json.sotlDate+'';
       				form.customer=_this.toString(json.customerName);
       				_this.gdID=_this.toString(json.customerId);	           			
       				form.sotlId=_this.toString(json.sotlId);
           			form.salStageNotes=_this.toString(json.salStageNotes);
           			form.custDemand=_this.toString(json.custDemand);
           			form.salTheme=_this.toString(json.salTheme);	 
           			form.salStageStop=_this.toString(json.salStageStop);
           			//salTage.push(json.salStagelabel+",value:'1324'");
           			if(json.salStagelabel!=null){
	           			form.salStage=_this.toString(json.salStagelabel);
	           			//记录当前的销售阶段
	           			_this.salStageCopy=form.salStage;
           			}else{
           				var salTage={};
           				salTage={label:["初期沟通"]};
           				console.log(salTage.label);
           				form.salStage=_this.toString(salTage.label);
           			}

           		//	_this.salStageValue=json.salStageValue+'';						           			
           			/*if(json==" "){
           				json=null;
           			}*/

           			form.salPossibility=_this.toString(json.salPossibilitylabel);
           			//_this.salPossibilityValue=json.salPossibilityValue+'';
           			
           			form.salSource=_this.toString(json.salSourcelabel);
           			form.sotlMoney=json.sotlMoney;
           		//	_this.salSourceValue=json.salSourceValue+'';
           			
           			form.salType=_this.toString(json.salTypelabel);
           		/*	if(json.salTypeValue!=null){
	           			_this.salTypeValue=json.salTypeValue+'';						           				
           			}else{
           				_this.salTypeValue="";
           			}*/			           			
           			//alert(json.customer);
       				form.contact=_this.toString(json.contactName);
       				_this.conID=_this.toString(json.contactId);	
       				
           			 if(array[1]!=0||array[1]!=null){
	           			console.log(array[1]);
	           			console.log("长度："+array[1].length);
	           			for(var i=0;i<array[1].length;i++){
	           				var salLog=array[1][i];
	           				//console.log();
	           				if(salLog.sotlMoney==''){
	           					salLog.sotlMoney=0.00;
	           				} 
	           				if(salLog.notes==''){
	           						salLog.notes='';
	           				} 
	           				if(_this.salesOpportunityTrackingLogs==null){
	           				_this.salesOpportunityTrackingLogs='';
	           				}
	           				_this.salesOpportunityTrackingLogs=_this.salesOpportunityTrackingLogs+"日期:"+salLog.updateTime+"\t"+"阶段:"+salLog.SotlStage+"("+salLog.sotlPossibility+")"+"\t"+salLog.UName+"\t"+"预计:"+salLog.sotlDate+"(￥"+salLog.sotlMoney+")"+"\t"+"备注:"+salLog.notes+"\n";                             
	           			}							           				
           			} 
		           				           		           			
				},
				//强制转换成String类型
				toString(val){
				return val==null?'':(val+'');
				},
				DeleteShow(salId){
					this.salId=salId;
					this.dialogDelete=true;
					
				},
				
		      //这里是加载外表，对应客户的方法
		     abroadsaleCustName() {
			   var _this=this;
			   //AllpageNumber			   
			 	axios.get("/sales/abroadsaleCustName",
		           			{
		           		params: {
		           			custName:_this.customer
		          			    }
		           			}
		           			//ajax请求成功的回调函数
		          			).then(function(response){					          				
		           			console.log("回调成功，获取了服务器端返回的值v");
		           			console.log("修改:"+response.data);					           		
		           		_this.restaurants=response.data;
		           	}).catch(function(){
		           		alert("加载外表,显示客户初始化数据出错了");
		           	});	//这个是数据的初始化
	          
			      },
		      //这里是加载外表，负责人的方法
		      abroadsaleAddUnameInfo(){
					 /*
					------------------加载负责人信息
					 */	
					 var _this=this;
					 
					 	axios.get("/sales/abroadsaleAddUnameInfo",
			           			//参数转换
			           			//Qs.stringify(this.form,{arrayFormat: 'brackets'})
			           			//ajax请求成功的回调函数
			           			{
					 				params:{
					 					uName: _this.soltId
					 				}
			           			}
			          			).then(function(response){					          				
			           			console.log("回调成功，获取了服务器端返回的值v");
			           			console.log("user:"+response.data);
							/*
							users:[
							{
								value: '选项1',
								label: '用户名1'					
							}
							]
							*/
				           	//_this.users=response.data;
				          	_this.restaurants=response.data;
			           		
			           	}).catch(function(){
			           		alert("加载外表,负责人信息出错了");
			           	});	  
		      },
				//这个是新增以及修改 表单提交事件
		      submitForm(formName) {
				//alert(this.form.salStage);
							var i=" ";
				    	    var obj = {};
							var _this=this;
							//销售阶段
							if(_this.form.salStage!=null&&_this.form.salStage!=''){
					    	    obj = this.stages.find((a)=>{
						    	      return a.label ===_this.form.salStage; 
						    	    });
						    	   if(obj!=null){
							    	    _this.form.salStage=obj.value;
						    }
						    	   //谁新建谁负责，谁修改谁负责
								if(_this.form.salStage!=_this.salStageCopy){
									_this.form.sotlId=document.cookie;
								}
		           				console.log("机会负责人:"+_this.form.sotlId);
							}else{
								_this.form.salStage='';
							}

				    	    console.log("销售阶段:"+_this.form.salStage);
				    	    //可能性
					    	 console.log("可能性:"+_this.form.salPossibility);					    	    
				    	    if(_this.form.salPossibility!=null&&_this.form.salPossibility!=''){
						    	   obj = this.possibilities.find((a)=>{
							    	      return a.label ===_this.form.salPossibility; 
							    	    });	
						    	   if(obj!=null){
							    	    _this.form.salPossibility=obj.value;  
						    	   }
			    	    	
				    	    }else{
				    	    	_this.form.salPossibility='1293';
				    	    }
				    	    console.log("可能性:"+_this.form.salPossibility);	
				    	    //来源 
				    	    if(_this.form.salSource!=null&&_this.form.salSource!=''){
					    	    obj = this.salSources.find((a)=>{
						    	      return a.label ===_this.form.salSource; 
						    	    });	
						    	   if(obj!=null){
							    	    _this.form.salSource=obj.value;	
						    	   }
				    	    	
				    	    }else{
				    	    	_this.form.salSource=" ";
				    	    }
				    	    console.log("来源:"+ _this.form.salSource);	
				    	    //类型
				    	   // alert(_this.form.salType);
				    	    //alert(_this.form.state);
				    	    if(_this.form.salType!=null&&_this.form.salType!=''){
					    	    obj = this.salTypes.find((a)=>{
						    	      return a.label ===_this.form.salType; 
						    	    });		
						    	   if(obj!=null){
							    	    _this.form.salType=obj.value;
						    	   }
				    	    }else{
				    	    	_this.form.salType=" ";
				    	    }  
				    	    console.log("类型:"+_this.form.salType);

				    	    if(_this.form.salStageStop==null||_this.form.salStageStop==''){
				    	    	_this.form.salStageStop="0天";
				    	    }

				    	    var str=_this.form.salStageStop;
				    	    str=str.split("天");
				    	   // console.log("停留时间:"+str[0]);
				    	    this.form.salStageStop=str[0]+'';
							i=this.form.customer;
							this.form.customer=this.gdID;
							var form = this.form;
							
							i=this.form.contact;
							this.form.contact=this.conID;
							
							/* i=this.form.salPossibility;
							 this.form.salPossibility=this.salPossibilityValue;
							 
							 i=this.form.salSource;
							 this.form.salSource=this.salSourceValue;
							 
							 i=this.form.salStage;
							 this.form.salStage=this.salStageValue;
							// salType
							 i=this.form.salType;
							 this.form.salType=this.salTypeValue;	*/							 
							
							//alert(form.salType);
							 
		        this.$refs[formName].validate((valid) => {
		          if (valid) {
			            //alert('submit!');

	           			//console.log("log:"+Qs.stringify(this.form,{arrayat: 'brackets'}))		
	           			console.log(JSON.stringify(form));
					 	axios.get("/sales/Addsale",
			           			//参数转换
			           			//Qs.stringify(this.form,{arrayFormat: 'brackets'})	
		           			{
		           		params:form 
		           			}


			           			//json.stringify(this.form)
			           			//ajax请求成功的回调函数
			          			).then(function(response){									    	  					          				
			          			_this.salesOpportunityTrackingLogs=null;					          			
			           			_this.$refs[formName].resetFields();//清空数据
					           			console.log("回调成功，获取了服务器端返回的值v");
					           			console.log(response.data);	
					           			_this.dialogFormVisible=false;
					           			if(_this.form.salId==null){
						           			_this.$notify({
							           	          title: '添加成功',
							           	          type: 'success',
							           	       	  duration:3000
							           	        });
						           			_this.page.AllpageNumber=_this.page.AllpageNumber+1;
					           			}else if(_this.form.salId!=null){
						           			_this.$notify({
							           	          title: '修改成功',
							           	          type: 'success',
							           	       	  duration:3000
							           	        });
					           			}else{
					           				
					           			}				     							           					           	
			           	}).catch(function(){
			           		_this.form.customer=i;
			           		alert("新增表单提交出错了");
			           	});				        	  
		          } else {
		            console.log('error submit!!');
		            return false;
		          }
		        });
		      },
				//删除方法
				Delete(){
					var _this=this;
				
					axios.get("/sales/Delete",
		           			//参数转换
		           			//Qs.stringify(this.form,{arrayFormat: 'brackets'})
		           			//ajax请求成功的回调函数
		           			{
								params:{
									salId:_this.salId
								}
		           			}
		          			).then(function(response){					          				
		           			console.log("回调成功，获取了服务器端返回的值v");
		           			console.log(response.data);

		           			//alert(_this.count);
			           			_this.$notify({
				           	          title: '删除成功',
				           	          type: 'success',
				           	       	  duration:3000
				           	        });
			           			/*
			           			-----------------------------刷新当前表单信息
			           			*/
			           			_this.page.AllpageNumber=_this.page.AllpageNumber-1;	
								console.log("当前页: "+_this.pageNumber);
								console.log("每页默认显示的条数:"+_this.pageCententSelect);
								_this.tableloading=true;
							 	axios.get("/sales/salePageable",
					           			{
					           		params: {
					          				pageNumber:_this.pageNumber,
					          				pageCentent:_this.pageCententSelect,
					          				DId:_this.DId
					          			    }
					           			}
					           			//ajax请求成功的回调函数
					          			).then(function(response){					          				
					           			console.log("回调成功，获取了服务器端返回的值v");
					           			console.log(response.data);
										_this.tableData3=response.data.saleOpp;
										_this.page.AllpageNumber=response.data.salesCount;
					     		 _this.tableloading=false;	
					           	}).catch(function(){
					           		alert("显示客户数据出错了");
					           	});	
							 	
		           			}).catch(function(){						           				
		           				alert("删除信息出错了");
		           			});
				},	
				//这个是列表的选择事件
				 handleSelect(item) {
				    	  var _this=this;	
					     //   console.log("当前的item的数值:"); 	
					      //  console.log(); 								        
				    	  if(item!=null){
						        console.log("value7Flag:"+this.value7Flag); 
				    		  if(this.value7Flag){							    			
					    		  _this.multipleSelection1(item);  
				    		  }
				    		  if(this.state1Session==true){
				    			  	  this.clearData();//清除搜索框的搜索条件
									 _this.searchSelect(item);	
									 //this.removeSearch=true;	
				    		  }
				    	  }else{
				    		
				    	  }	
						 	
				    	  //这里是处理选择对应客户之后，相应的赋值
				    	  if(item.conName!=null){
					    	  var contacts=[{con:item.label2,conlabel:item.conName}];
						        console.log("item:"+item.conName);
						        this.contacts=contacts;		
						        this.form.contact=item.conName;
			           			this.conID=item.label2;
				    	  }
					       if(item.label1!=null){
					        	  this.gdID=item.label1;
					        }
					      
					      },
							 //这个是显示查询的数据
							 querySearchAsync(queryString, cb) {

							        var restaurants = this.restaurants;				       
							        var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;	
							        
							      	console.log("results:"+results);//查看返回结果如果不为空则表示在当前列表中存在比配值，为空表示没有比配值									        
									        if(queryString==null||queryString.length==0){
												if(this.customerFlag){
											    	 this.customer=null;
											    	  this.abroadsaleCustName();
															
												}
									        	if(this.soltIdFlag){
												     this.soltId=null;															    	 
											    	 this.abroadsaleAddUnameInfo(); 												        	 		
									        	 }

    
										        clearTimeout(this.timeout);
										        this.timeout = setTimeout(() => {
										       	cb(this.restaurants);
										       }, 3000* Math.random());	
									        }else{
										      	if(results==''){
															    	  console.log("queryString3:"+queryString);	
					
																	if(this.customerFlag){
																    	 this.customer=queryString;
																    	  this.abroadsaleCustName();																		
																	}
															        if(this.soltIdFlag){
																	     this.soltId=queryString;;															    	 
																    	 this.abroadsaleAddUnameInfo(); 
														        	 		
															        }
																	        clearTimeout(this.timeout);
																	        this.timeout = setTimeout(() => {
																	       ;
																	       	cb(this.restaurants);
																	       }, 3000* Math.random());		     

									       					 }else{
															        clearTimeout(this.timeout);
															        this.timeout = setTimeout(() => {												     
															       	cb(results);
															       }, 1000* Math.random());
															        
														        }
															    	  
									    }						
							      },
			    //这个是根据输入的内容筛选数据
			   createStateFilter(queryString) {
			        return (state) => {return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);};
			      }, 
	},
			 mounted() {	
				this.initForm(this.json);
				console.log(this.json);
				//console.log(this.json[0].contactName);
		    	/*
		    	*
		    	数据筛选下拉框加载数据,加载字典信息
		    	*/					
					var _this = this;
           			var form='';
       				form=_this.form;
				 	axios.post("/sales/saleAddDictionaryInfo",
		           			//参数转换id
		           			//Qs.stringify(this.form,{arrayFormat: 'brackets'})
		           			//ajax请求成功的回调函数
		          			).then(function(response){					          				
		           			console.log("回调成功，获取了服务器端返回的值v");
		           			console.log(response.data);
		     		 //source 来源
		     		 //possibilities 可能性
		     		 //stages 销售阶段
		           		_this.possibilities=response.data[0];
			           	_this.salSources=response.data[1];	
			           	_this.stages=response.data[2];	
			           	_this.salTypes=response.data[3];
			           	
		           	}).catch(function(){
		           		alert("加载字典信息出错了");
		           	});	
				//获取当前登录用户的编号
				var arr=new Array();
				var Id='';
					arr=document.cookie;
					console.log("当前用户的cookie:"+arr);
			}
	}
						var Ctor = Vue.extend(Main1)
					//bigbox
					new Ctor().$mount('#bigbox')
/*---------------------------------------------------------------------------------------------------------------------*/							   
							   
		</script>
</html>
